#include "raster.hpp"

namespace hms::raster
{

Raster::
Raster(
	ArrayXXs&& values,
	scalar  cellsize,
	Array2s bottomLeft,
	bool    useCorners,
	scalar  noDataValue
) :
	m_values { std::move(values) },
	m_cellsize { cellsize },
	m_bottomLeft { storeBottomLeft(cellsize, std::move(bottomLeft), useCorners) },
	m_noDataValue { noDataValue }
{}

Raster::Raster(
	scalar  cellsize,
	Array2s bottomLeft,
	bool    useCorners,
	scalar  noDataValue
) :
	Raster( {}, cellsize, std::move(bottomLeft), useCorners, noDataValue )
{}

Raster::Raster(
	scalar cellsize,
	scalar bottomLeftX,
	scalar bottomLeftY,
	bool   useCorners,
	scalar noDataValue
) :
	Raster(cellsize, Array2s{bottomLeftX, bottomLeftY}, useCorners, noDataValue)
{}

auto Raster::values() const -> const ArrayXXs& {
	return m_values;
}

void Raster::values( ArrayXXs&& valuesArg ){
	m_values = std::move(valuesArg);
}

auto Raster::size() const -> Array2i {
	return { m_values.rows(), m_values.cols() };
}

auto Raster::nx() const -> Index {
	return m_values.rows();
}

auto Raster::ny() const -> Index {
	return m_values.cols();
}

auto Raster::cellsize() const -> scalar {
	return m_cellsize;
}

void Raster::cellsize( scalar cellsizeArg ){
	m_cellsize = cellsizeArg;
}

auto Raster::bottomLeft() const -> const Array2s& {
	return m_bottomLeft;
}

void Raster::bottomLeft( Array2s bottomLeftArg ){
	m_bottomLeft = std::move(bottomLeftArg);
}

auto Raster::noDataValue() const -> scalar {
	return m_noDataValue;
}

void Raster::noDataValue( scalar val ){
	m_noDataValue = val;
}

Array2s Raster::storeBottomLeft(
	scalar cellsizeArg, Array2s bottomLeftArg, bool useCornersArg
){
	if (useCornersArg)
		return bottomLeftArg;
	else
		return bottomLeftArg - (cellsizeArg/2);
}

} // namespace hms::raster
